// Call

// ES 5
Function.prototype.myCall = function (context) {
  if (typeof this !== 'function') {
    throw 'caller must be a function'
  }

  context = context || window

  context.fn = this

  var arg = []

  for (var i=1; i<arguments.length; ++i) {
    arg.push('arguments[' + i + ']')
  }

  var res = eval('context.fn(' + arg + ')')

  delete context.fn

  return res
}



// ES 6 
Function.prototype.myCall = function (context) {
  if (typeof this !== 'function') {
    throw 'caller must be a function'
  }
  context = context || window

  context.fn = this
  
  let arg = [...arguments].slice(1)
  let res = context.fn(...arg)

  delete context.fn

  return res
}




